const app = getApp();
Page({
  data: {
    userid: '',
    key: 'ZhangQiwen5299',
    beginDate: '',
    endDate: '',
    items: [],
  },
  onLoad(query) {
    // dd.alert({ title: app.globalData.userid });
    // dd.alert({ title: app.globalData.key });
    // 页面加载
    dd.showLoading({
      content: '加载中...',
      delay: 1000,
    });
    var that = this;
    dd.httpRequest({
      url: 'http://www.ejzcat.com/DingApi/GetQueryDate.ashx',
      method: 'POST',
      data: {
        n: 6
      },
      dataType: 'json',
      async: false,
      success: function(res) {
        dd.hideLoading();
        that.setData({
          beginDate: res.data.beginDate,
          endDate: res.data.endDate
        })
      },
      fail: function(err) {
        dd.alert({ content: JSON.stringify(err) });
      }
    });
  },
  selectBegin(e) {
    // 收起键盘
    dd.hideKeyboard();
    var that = this;
    dd.datePicker({
      currentDate: that.beginDate,
      // startDate: that.beginDate,
      // endDate: that.beginDate,
      success: (res) => {
        that.setData({
          beginDate: res.date
        })
      },
    });
  },
  selectEnd(e) {
    // 收起键盘
    dd.hideKeyboard();
    var that = this;
    dd.datePicker({
      currentDate: that.endDate,
      // startDate: that.endDate,
      // endDate: that.endDate,
      success: (res) => {
        that.setData({
          endDate: res.date
        })
      },
    });
  },
  queryData() {
    // 页面加载
    dd.showLoading({
      content: '加载中...',
      delay: 1000,
    });
    var that = this;
    var beginDate = this.data.beginDate;
    var endDate = this.data.endDate;
    dd.httpRequest({
      url: 'http://www.ejzcat.com/DingApi/EquipmentRepair/Query.ashx',
      method: 'POST',
      data: {
        beginDate: beginDate,
        endDate: endDate,
        status: 1,
        userid: app.globalData.userid
      },
      dataType: 'json',
      async: false,
      success: function(res) {
        dd.hideLoading();
        if (res.data.Items.length == 0) {
          dd.alert({ content: '暂无数据' });
        }
        that.setData({
          items: res.data.Items,
        });
      },
      fail: function(err) {
        dd.alert({ content: JSON.stringify(err) });
      }
    });
  },
  onMessage(e) {
    var id = e.currentTarget.id;
    //dd.alert({ content: e.currentTarget.id });
    dd.navigateTo({
      url: '../../../mypages/equipment/message/message?id=' + id,
    })
  },
})